import createAxios from '../utils/axios'


// 获取主分类下子分类接口
export const getRecommendClassify = (id: number) => {
    return createAxios({
        url: `/api/get/index/classify?main_classify_id=${id}`,
        method: 'GET',
    }, 'API1', {loading: true});
}
// 获取分类下所有商品
export const getClassifyDetail = (params: any) => {
    return createAxios({
        url: `/shop/goods/classifyDetail?classify_id=${params.id}&page=${params.page}&page_size=${params.pageSize}&type=${params.type}&attribute_value_ids=${JSON.stringify(params.ids)}`,
        method: 'GET',
    }, 'API1', {loading: true});
}
// 根据分类ID获取一级分类属性
export const getClassifyAttributes = (id: any) => {
    return createAxios({
        url: `/shop/classify/getAttributes?classify_id=${id}`,
        method: 'GET',
    }, 'API1', {loading: true});
}
// 收藏列表
export const getFavoriteList = () => {
    return createAxios({
        url: '/shop/user_favorite/list?page=1&page_size=200',
        method: 'GET',
    }, 'API1', {loading: false});
}

// 取消收藏
export const delFavorite = (params:any) => {
    return createAxios({
        url: '/shop/user_favorite/delete',
        method: 'POST',
        data: params,
    }, 'API1', {loading: false});
}
// 商品筛选条件返回
export const filterGoods = (mainId: number | string, subId: number | string) => {
    return createAxios({
        url: `/api/goods/filter?main_classify_id=${mainId}&son_classify_id=${subId}`,
        method: 'GET',
    }, 'API1', {loading: true});
}
// 筛选后商品列表
export const filterGoodsList = (params: any) => {
    return createAxios({
        url: `/api/goods-filter/list?page=${params.page}&pagesize=${params.pageSize}&type=${params.type}&attribute_value_ids=${JSON.stringify(params.ids)}`,
        method: 'GET',
    }, 'API1', {loading: true});
}
// 热度商品列表
export const hotGoodsList = () => {
    return createAxios({
        url: `/api/hot/goods?page=1&pagesize=24`,
        method: 'GET',
    }, 'API1', {loading: false});
}
// 热度商品列表
export const getSearchGoodsList = (params: any) => {
    return createAxios({
        url: `/shop/goods?page=${params.page}&page_size=${params.pageSize}&goods=${params.goods}`,
        method: 'GET',
    }, 'API1', {loading: true});
}
// 地址列表
export const getUserAddress = (id: number) => {
    return createAxios({
        url: `/shop/userAddress?user_id=${id}`,
        method: 'GET',
    },'API1',{loading:true});
}
// 新建地址
export const addUserAddress = (params: any) => {
    return createAxios({
        url: '/shop/userAddress/add',
        method: 'POST',
        data: params,
    },'API1',{loading:false});
}
// 修改地址
export const editUserAddress = (params: any) => {
    return createAxios({
        url: '/shop/userAddress/edit',
        method: 'POST',
        data: params,
    },'API1',{loading:false});
}
// 删除地址
export const deleteUserAddress = (params: any) => {
    return createAxios({
        url: '/shop/userAddress/delete',
        method: 'POST',
        data: params,
    },'API1',{loading:false});
}
//默认地址
export const setDefaultAddress = (params: any) => {
    return createAxios({
        url: '/shop/user_address/setDefault',
        method: 'POST',
        data: params,
    },'API1',{loading:false});
}
//地址详情
export const getDetailAddress = (id: number) => {
    return createAxios({
        url: `/shop/userAddress/detail?id=${id}`,
        method: 'GET',
    },'API1',{loading:true});
}

//兑换积分列表
export const couponCenter = () => {
    return createAxios({
        url: `/shop/coupon/center`,
        method: 'GET',
    }, 'API1', {loading: false});
}

export const couponReceive = (params: any) => {
    return createAxios({
        url: '/shop/coupon/receive',
        method: 'POST',
        data: params,
    },'API1',{loading:true});
}
//获取主体商品详情
export const getDetail = (id: string) => {
  return createAxios({
      url: `/shop/goods/detail?id=${id}`,
      method: 'GET',
  }, 'API1');
}


//增加商品访问量
export const addVisit = (params: any) => {
  return createAxios({
      url: `/shop/goods/addVisit`,
      method: 'POST',
      data: params,
  }, 'API1',{loading:false});
}


//增加商品收藏
export const addFavorite = (id: string) => {
  return createAxios({
      url: `/shop/userFavorite/add`,
      method: 'POST',
      data: { 'goods_id': id },
  }, 'API1');
}

//取消商品收藏
export const deleteFavorite = (id: string) => {
  return createAxios({
      url: `/shop/userFavorite/delete`,
      method: 'POST',
      data: { 'goods_id': id },
  }, 'API1');
}

//商品收藏列表
export const listFavorite = () => {
  return createAxios({
      url: `/shop/userFavorite/list`,
      method: 'GET',
  }, 'API1');
}
//获取购物车
export const getCarts = () => {
    return createAxios({
        url: '/shop/userCart?page=1&page_size=50',
        method: 'GET',
    },'API1');
}
//加入购物车
export const addCarts = (params: any) => {
    return createAxios({
        url: '/shop/userCart/add',
        method: 'POST',
        data: params,
    },'API1',{loading:false});
}
//删除购物车商品
export const deleteCarts = (params: any) => {
    return createAxios({
        url: '/shop/userCart/delete',
        method: 'POST',
        data: params,
    },'API1',{loading:false});
}
//删除购物车全部商品
export const clearCarts = (params: any) => {
    return createAxios({
        url: '/shop/userCart/clear',
        method: 'POST',
        data: params,
    },'API1',{loading:false});
}
